import 'dart:convert';
// dart 中的类

class Student {
  var sname, sage;
  Student(this.sname, this.sage);

  Student.fromJSON(json):
    this.sname = json['sname'],
    this.sage = json['sage'];

  intr() {
    print("我叫: ${this.sname}，我今年: ${this.sage}岁了。");
  }

  @override
  String toString() {
    return "Student: { sname: ${this.sname}, sage: ${this.sage} }";
  }
}

class Student2 {
  var firstName, lastName, fullName;

  Student2(firstName, lastName):
    this.firstName = firstName,
    this.lastName = lastName,
    this.fullName = firstName + " " + lastName;

  @override
  String toString() {
    return "Student2: { firstName: ${this.firstName}, lastName: ${this.lastName}, fullName: ${this.fullName}}";
  }
}

// 入口主函数
void main() {
  var tom = Student("Tom", 18);
  print(tom);
  tom.intr();

  var eric = Student2("Eric", "Evans");
  print(eric);

  var json = '{ "sname": "Eric", "sage": 18 }';
  var eric2 = Student.fromJSON(jsonDecode(json));
  print(eric2);
}
